var express = require('express');
var router = express.Router();
var NoteDao = require("../my_modules/NoteDao");
var events = require("events");

/**
 * 初始化首页数据
 */
router.get('/', function(req, res, next) {
  var emitter = new events.EventEmitter();
  emitter.on("selectAllNoteSuccess" ,function (result) {
     res.render('index', { title: 'love note -  世界第一爱墙！ - 爱她(他)就给她(他)最好的 ', noteList:result});
  });
  emitter.on("selectAllNoteError",function (error) {
      res.render('index', { title: 'Express',errMsg:error });
  });
    var noteDao = new NoteDao();
    noteDao.selectAll(retList);
    //回调函数
    function retList(emitLabel,result) {
        emitter.emit(emitLabel,result);
    }
});

module.exports = router;
